
; Test cases for function calls

(define-test-suite call-tests "call-tests" (lambda ()
   
  (arith-test apply (apply + '()) "(apply + '())" 0)
  (arith-test apply (apply + '(1)) "(apply + '(1))" 1)
  (arith-test apply (apply + 1 '()) "(apply + 1 '())" 1)
  (arith-test apply (apply + '(1 2)) "(apply + '(1 2))" 3)
  (arith-test apply (apply + 1 '(2)) "(apply + 1 '(2))" 3)
  (arith-test apply (apply + 1 2 '()) "(apply + 1 2 '())" 3)
  (arith-test apply (apply + '(1 2 3)) "(apply + '(1 2 3))" 6)
  (arith-test apply (apply + 1 2 '(3)) "(apply + 1 2 '(3))" 6)
  (bool-test apply (apply < '(1 2)) "(apply < '(1 2))" #t)
  (bool-test apply (apply < 1 '(2)) "(apply < 1 '(2))" #t)
  (bool-test apply (apply < 1 2 '()) "(apply < 1 2 '())" #t)
  (bool-test apply (apply < '(1 2 3)) "(apply < '(1 2 3))" #t)
  (bool-test apply (apply < 1 2 '(3)) "(apply < 1 2 '(3))" #t)
  (arith-test apply (apply apply (list + '(1 2 3)))
	      "(apply apply (list + '(1 2 3)))" 6)
  (arith-test apply (apply apply (list + 1 2 '(3)))
	      "(apply apply (list + 1 2 '(3)))" 6)
  (arith-test apply (apply + (apply apply list 1 '(2 (3))))
	      "(apply + (apply apply list 1 '(2 (3))))" 6)
  (arith-test apply (apply apply (list + 1 2 3 '()))
	      "(apply apply (list + 1 2 3 '()))" 6)
  (arith-test apply (apply apply + 1 '(2 3 ())) "(apply apply + 1 '(2 3 ())" 6)
  (arith-test apply (apply apply + 1 '(2 (3))) "(apply apply + 1 '(2 3 ())" 6)
  (arith-test apply (apply apply + 1 2 3 '(())) "(apply + 1 2 3 '(()))" 6)
  
  ; call/cc test
  ;
  (thunk-test "current-cont, with-continuation"
    (lambda ()
      ((lambda (cont)
         (with-continuation cont (lambda () #t)))
       (current-cont))))

  ; returning values, call-with-values
  ;
  (arith-test ((lambda () 1)) "((lambda () 1))" 1)
  
  (thunk-test values "values"
    (lambda ()
      (call-with-values
        (lambda ()
          (values 10 1 2 3 4))
        (lambda (ten one two three four)
          (= (+ one two three four) ten)))))
      
  (thunk-test "values  (applied)"
    (lambda ()
      (call-with-values
        (lambda ()
          (apply values 10 1 2 '(3 4)))
        (lambda (ten one two three four)
          (= (+ one two three four) ten)))))
        
  (thunk-test "values  (with rest list)"
    (lambda ()
      (call-with-values
        (lambda ()
          (values 10 1 2 3 4))
        (lambda (ten one two . rest)
          (and 
            (= (+ one two (car rest) (car (cdr rest))) ten)
            (null? (cdr (cdr rest))))))))        
     
  (thunk-test "values  (inside if)"
    (lambda ()
      (call-with-values
        (if #t
            (lambda () (values 1 2))
            (lambda () (values 3 4)))
        (lambda (one two)
          #t))))
     
  ))